package ProjectManagement;

import com.spm.pojo.StudentChooseCourse;
import com.spm.utils.StudentMapperUtil;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
import com.spm.pojo.Teacher;
@WebServlet(name = "teacherclassselection",value = "/teacherclassselection")
public class teacherclassselection extends HttpServlet {

    private static final long serialVersionUID = 1L;

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        this.doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        HttpSession session=request.getSession();
        String courseid = (String) request.getParameter("courseid");
        Teacher teacher=(Teacher) session.getAttribute("teacher");
        session.setAttribute("courseid",courseid);
        List<StudentChooseCourse> studentChooseCourses = new StudentMapperUtil().selectClassChooseStudentListByTnoAndCno(teacher.getTid(), courseid);
        request.setAttribute("studentChooseCourses",studentChooseCourses);
        teacherclassselection(request,response);
    }
    /**
     * 确认学生选课-实现页面跳转
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void teacherclassselection(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
        String mainPage = "teacherclassselection.jsp";
        request.setAttribute("mainPage", mainPage);
        RequestDispatcher dispatcher = request.getRequestDispatcher("/ProjectManagement/main.jsp");
        dispatcher.forward(request, response);
    }
}
